# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=flex
pkgver=2.6.0
pkgrel=1
pkgdesc="A tool for generating text-scanning programs"
arch=('i686' 'x86_64')
url="http://flex.sourceforge.net"
license=('custom')
groups=('base' 'base-devel')
depends=('m4' 'sh' 'libiconv' 'libintl')
makedepends=('libiconv-devel' 'gettext-devel')
options=('staticlibs')
install=flex.install
source=(http://downloads.sourceforge.net/sourceforge/flex/flex-${pkgver}.tar.bz2
        flex-2.5.38-msys2.patch
        without-pdf.patch)
md5sums=('266270f13c48ed043d95648075084d59'
         '2e354f36bfc87fcd7db775a8a45f0aec'
         '63bf849ab787cb02836a60c166807a06')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}

  patch -p1 -i ${srcdir}/flex-2.5.38-msys2.patch
  patch -p1 -i ${srcdir}/without-pdf.patch

  ./autogen.sh
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --without-libiconv-prefix \
    --without-libintl-prefix \
    --enable-static \
    --disable-shared

  make
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}

  # these tests used features removed in bison-2.6
  sed -i -e '/test-bison-yylloc/d' -e '/test-bison-yylval/d' tests/Makefile.in

  make check
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}

  make DESTDIR=${pkgdir} install
  cp -f ${pkgdir}/usr/bin/flex.exe ${pkgdir}/usr/bin/flex++.exe
  cp -f ${pkgdir}/usr/bin/flex.exe ${pkgdir}/usr/bin/lex.exe

  install -Dm644 COPYING ${pkgdir}/usr/share/licenses/${pkgdir}/license.txt
}
